﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.MVVM
{
    public abstract class BaseViewModel : NotifyObject
    {
        public static Microsoft.Phone.Controls.PhoneApplicationFrame PhoneApplicationFrame { get; set; }
        public BaseViewModel()
        {
            if (PhoneApplicationFrame != null)
                PhoneApplicationFrame.Navigated += frame_Navigated;
        }

        //internal G.Navigate.GBasePage Page { get; private set; }

        protected G.Navigate.NavigationContext NavigationContext
        {
            get;
            private set;
        }

        #region 导航相关
        void frame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            PhoneApplicationFrame.Navigated -= frame_Navigated;
            G.Navigate.GBasePage Page = e.Content as G.Navigate.GBasePage;
            this.NavigationContext = Page.NavigationContext;
            Page.ViewModel = this;
            OnNavigatedTo(e);
        }
        //internal void OnNavigatedTo_Internal(System.Windows.Navigation.NavigationEventArgs e)
        //{
        //    OnNavigatedTo(e);
        //}
        protected virtual void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { }

        //internal void OnNavigatedFrom_Internal(System.Windows.Navigation.NavigationEventArgs e)
        //{
        //    OnNavigatedFrom(e);
        //}
        //protected virtual void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { }

        //internal void OnNavigatingFrom_Internal(System.Windows.Navigation.NavigatingCancelEventArgs e)
        //{
        //    OnNavigatingFrom(e);
        //}
        //protected virtual void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e) { }

        //internal void OnNavigatingBackFrom_Internal(G.Navigate.NavigateBackFromEventArgs e)
        //{
        //    OnNavigatingBackFrom(e);
        //}
        //protected virtual void OnNavigatingBackFrom(G.Navigate.NavigateBackFromEventArgs e) { }

        //internal void OnNavigatingFromBack_Internal(G.Navigate.NavigateBackFromEventArgs e)
        //{
        //    OnNavigatingFromBack(e);
        //}

        //protected virtual void OnNavigatingFromBack(G.Navigate.NavigateBackFromEventArgs e) { }

        #endregion

        private bool isEnable = true;
        public bool IsEnable
        {
            get
            {
                return isEnable;
            }
            private set
            {
                if (isEnable != value)
                {
                    isEnable = value;
                    this.NotifyPropertyChanged("IsEnable");
                }
            }
        }

        private bool isBeginProgress;
        public bool IsBeginProgress
        {
            get
            {
                return isBeginProgress;
            }
            set
            {
                if (value != isBeginProgress)
                {
                    isBeginProgress = value;
                    this.IsEnable = !value;
                    this.NotifyPropertyChanged("IsBeginProgress");
                }
            }
        }
    }
}
